package goleetcode

func addMinimum(word string) int {
	// A string is called valid if it can be formed by concatenating the string "abc" several times
	// define d[i] = min (d[i-1] + 2, d[i-1] - 1)
	n := len(word)
	d := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		d[i] = d[i - 1] + 2
		if i > 1 && word[i - 1] > word[i - 2] {
			d[i] = d[i - 1] - 1		
		}
	}
	return d[n]
}